package com.songtech.server.entry;

import com.songtech.server.utils.GetKeysUtils;

import java.io.Serializable;
import java.time.LocalTime;

/**
 * Create By YINN on 2018/4/6 16:38
 * Description : 基础协议实体类(各个协议需要继承当前实体类)
 */
public class BaseProtocal implements Serializable {

    private static final String ORI_POS_FLAG = "ori";

    //制造商
    protected String manufacturer;

    //终端身份标识
    protected String imei;

    //命令号
    protected String cmd;

    //命令时间 时分秒
    protected LocalTime cmdTime;

    //命令参数 数组(按顺序装入剩余参数值)
    protected String[] cmdParam;

    //点亮
    protected String dumpEnergy;

    private String redisKey;

    private String oriKey;



    public BaseProtocal() {
    }

    public BaseProtocal(String manufacturer, String imei, String cmd, LocalTime cmdTime, String[] cmdParam) {
        this.manufacturer = manufacturer;
        this.imei = imei;
        this.cmd = cmd;
        this.cmdTime = cmdTime;
        this.cmdParam = cmdParam;
        this.redisKey = GetKeysUtils.combineAnyKeys(cmd,imei);
    }

    /**
     * 必须重写此方法
     * 将cmdParam中值赋予特性协议中剩余值
     * 重写后 先调用super.setAll()
     * 再给其他值赋值
     * */
    public void setAll(String manufacturer, String imei, String cmd, LocalTime cmdTime, String[] cmdParam){
        this.manufacturer = manufacturer;
        this.imei = imei;
        this.cmd = cmd;
        this.cmdTime = cmdTime;
        this.cmdParam = cmdParam;
        this.redisKey = GetKeysUtils.combineAnyKeys(cmd,imei);
    }

    public String makeOriKey(){

        return GetKeysUtils.combineAnyKeys(cmd,ORI_POS_FLAG,imei);

    }



    public String getRedisKey() {
        return redisKey;
    }

    public void setRedisKey(String redisKey) {
        this.redisKey = redisKey;
    }

    public String getManufacturer() {
        return manufacturer;
    }

    public void setManufacturer(String manufacturer) {
        this.manufacturer = manufacturer;
    }

    public String getImei() {
        return imei;
    }

    public void setImei(String imei) {
        this.imei = imei;
    }

    public String getCmd() {
        return cmd;
    }

    public void setCmd(String cmd) {
        this.cmd = cmd;
    }

    public LocalTime getCmdTime() {
        return cmdTime;
    }

    public void setCmdTime(LocalTime cmdTime) {
        this.cmdTime = cmdTime;
    }

    public String[] getCmdParam() {
        return cmdParam;
    }

    public void setCmdParam(String[] cmdParam) {
        this.cmdParam = cmdParam;
    }

    public String getOriKey() {
        return oriKey;
    }

    public void setOriKey(String oriKey) {
        this.oriKey = oriKey;
    }

    public String getDumpEnergy() {
        return dumpEnergy;
    }

    public void setDumpEnergy(String dumpEnergy) {
        this.dumpEnergy = dumpEnergy;
    }
}
